package com.example.peanutsubway.web;

import com.alibaba.fastjson.JSONObject;
import com.example.peanutsubway.annotation.ResponseTypeAnnotation;
import com.example.peanutsubway.entity.ChannelSort;
import com.example.peanutsubway.entity.PageInfo;
import com.example.peanutsubway.myEnum.ResponseEnum;
import com.example.peanutsubway.service.impl.ChannelSortServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/10/13-17:12
 * @Since:jdk1.8
 * @Description:
 */


@WebServlet("/channelSort.do")
public class ChannelSortServlet extends BaseServlet<ChannelSort> {
    private ChannelSortServiceImpl channelSortService = new ChannelSortServiceImpl();

    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String showALLChannelSort(ChannelSort channelSort) {
        String nowPage = request.getParameter("nowPage");
        String pageNum = request.getParameter("pageSize");
        PageInfo pageInfo = channelSortService.showChannelSort(channelSort, pageNum, nowPage);
        String jsonString = JSONObject.toJSONString(pageInfo);
        return jsonString;
    }

    /**
     * 显示
     * @param channelSort
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String showALLChannelf(ChannelSort channelSort) {
        List<ChannelSort> channelSorts = channelSortService.ChannelSortfid(channelSort);
        String jsonString = JSONObject.toJSONString(channelSorts);
        return jsonString;
    }

    /**
     * 根据父级id 显示子级
     * @param channelSort
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String showALLChannelS(ChannelSort channelSort) {
        List<ChannelSort> channelSorts = channelSortService.channelSortSid(channelSort.getFid());
        String jsonString = JSONObject.toJSONString(channelSorts);
        return jsonString;
    }

    /**
     * 添加
     * @param channelSort
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String addChannel(ChannelSort channelSort) {
        Boolean aBoolean = channelSortService.addChannelSort(channelSort);
        String message = aBoolean ? "添加成功" : "添加失败";
        return message;
    }

    /**
     * 删除
     * @param channelSort
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String deleteChannel(ChannelSort channelSort) {
        Boolean aBoolean = channelSortService.deleChannelSort(channelSort.getCid());
        String message = aBoolean ? "删除成功" : "删除失败";
        return message;
    }

    /**
     * 修改
     * @param channelSort
     * @return
     */
    @ResponseTypeAnnotation(type = ResponseEnum.AJAX)
    public String updateChannel(ChannelSort channelSort) {
        Boolean aBoolean = channelSortService.updateChannelSort(channelSort);
        String message = aBoolean ? "修改成功" : "修改失败";
        return message;
    }
}
